# Contributor: Jakub Jirutka <jakub@jirutka.cz>
# Maintainer: Jakub Jirutka <jakub@jirutka.cz>
pkgname=lua-lcurses
_rockname=${pkgname#lua-}
pkgver=9.0.0
pkgrel=0
pkgdesc="Lua bindings for Curses"
url="https://lcurses.github.io/lcurses"
arch="all"
license="MIT"
depends="lua"
makedepends="autoconf automake libtool ncurses-dev"
subpackages=""
options="!check"  # FIXME requires lua-specl that we don't have yet
source="$pkgname-$pkgver.tar.gz::https://github.com/lcurses/$_rockname/archive/release-v$pkgver.tar.gz
	bootstrap.patch"
builddir="$srcdir/$_rockname-release-v$pkgver"

# 5.3 fails to build
_luaversions="5.1"
for _v in $_luaversions; do
	makedepends="$makedepends lua$_v-dev"
	subpackages="$subpackages lua$_v-${pkgname#lua-}:_subpackage"
done

prepare() {
	default_prepare

	cd "$builddir"
	./bootstrap --skip-git

	update_config_sub
	update_config_guess

	local lver; for lver in $_luaversions; do
		cp -r "$builddir" "$builddir-$lver"
	done
}

build() {
	local lver; for lver in $_luaversions; do
		msg "Building for Lua $lver"

		cd "$builddir-$lver"
		./configure \
			--build=$CBUILD \
			--host=$CHOST \
			--prefix=/usr \
			LUA=lua$lver \
			LUA_INCLUDE=$(pkg-config --cflags-only-I lua$lver)
		make
	done
}

package() {
	mkdir -p "$pkgdir"
}

_subpackage() {
	local lver="${subpkgname:3:3}"
	pkgdesc="$pkgdesc (for Lua $lver)"
	depends="lua$lver"
	install_if="$pkgname=$pkgver-r$pkgrel lua$lver"
	local rockdir="$subpkgdir/usr/lib/luarocks/rocks-$lver/$_rockname/$pkgver-1"

	cd "$builddir-$lver"
	make DESTDIR="$subpkgdir" install

	rm -r "$subpkgdir"/usr/share/doc

	mkdir -p "$rockdir"
	echo 'rock_manifest = {}' > "$rockdir"/rock_manifest
}

sha512sums="4c6b4cf95f1ec91ac7c990c102c7e25716bb8083a25cc03812df04466dff4717d46fcabebdc37abc2596245ef3b072821294368d8a060db72f3c7922938c8371  lua-lcurses-9.0.0.tar.gz
b9d861ba7aa66d16a92bc3f5086daecfc26d150e7aa787ffbf13cf0bd09eba00e602c509010d4942a25f186857abbbe85ae76f7bae5f1dc7fb43d376e0656cc0  bootstrap.patch"
